﻿using System;
using Microsoft.SqlServer.Dts.Runtime;
 

namespace MySSISComponents
{
    [DtsTask
    (
        DisplayName = "MyDeleteFile",
        Description = "Delete file "
    )
    ]
  public  class MyDeleteFile:Task
    {
        private string fileName = "";
        private bool fileDeleted = false;

        public override DTSExecResult Execute(Connections cons,
           VariableDispenser vars, IDTSComponentEvents events,
           IDTSLogging log, Object txn)
        {
            try
            {
                if (this.fileName == "")
                {
                    events.FireWarning(0, "SampleTask", "No file specified.", "", 0);
                    this.fileDeleted = false;
                }
                else
                {
                    if (System.IO.File.Exists(this.fileName))
                    {
                        System.IO.File.Delete(this.fileName);
                        this.fileDeleted = true;
                    }
                    else
                        this.fileDeleted = false;
                }
                return DTSExecResult.Success;
            }
            catch (System.Exception exception)
            {
                //   Capture the exception and post an error.
                events.FireError(0, "Sampletask", exception.Message, "", 0);
                return DTSExecResult.Failure;
            }
        }
        public string FileName
        {
            get { return this.fileName; }
            set { this.fileName = value; }
        }
        public override object ExecutionValue
        {
            get { return this.fileDeleted; }
        }


    }
}
